package com.sgb.kjwl.view.ui.activity.self;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityLogisticsMenuBinding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.sgb.kjwl.model.entity.self.PermissionMenuEntity;
import com.sgb.kjwl.view.ui.activity.self.logistics.BargainingActivity;
import com.sgb.kjwl.view.ui.activity.self.logistics.CargoManageActivity;
import com.sgb.kjwl.view.ui.activity.self.logistics.CarriageBusinessActivity;
import com.sgb.kjwl.view.ui.activity.transport.owner.TransportOrderOwnerActivity;
import com.sgb.kjwl.view.ui.adapter.self.SelfSecondOrderNestingAdapter;
import com.sgb.kjwl.viewmodel.self.LogisticsMenuModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * 个人中心物流中介菜单
 * by wangbinchen
 */
public class LogisticsMenuActivity extends AppActivity {
    ActivityLogisticsMenuBinding binding;
    @Inject
    LogisticsMenuModel viewModel;
    private int colum = 4;
    private int row = 2;
    private SelfSecondOrderNestingAdapter adapter;
    private List<PermissionMenuEntity.ListEntity> datas=new ArrayList<>();
    public static void start(Context context) {
        Intent intent = new Intent(context,  LogisticsMenuActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }
    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerSelfComponent.builder().appComponent(appComponent).selfModule(new SelfModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        binding= DataBindingUtil.setContentView(this, R.layout.activity_logistics_menu);
        binding.setViewModel(viewModel);
        //设置头部信息
        binding.include.titleView.setText("物流中介");
        //返回按钮的事件
        binding.include.ivBack.setOnClickListener(this);
        adapter = new SelfSecondOrderNestingAdapter(getActivity(), null);
        binding.rvMenu.setAdapter(adapter);
        binding.rvMenu.setLayoutManager(new GridLayoutManager(getActivity(), colum));
        adapter.setCount(colum * row);
        viewModel.getMenus(datas);
        adapter.setDatas(datas);
        adapter.setOnItemClick(new AdapterOnItemClick<PermissionMenuEntity.ListEntity>() {
            @Override
            public void onItemClick(PermissionMenuEntity.ListEntity listEntity, int position) {
                switch (listEntity.getTitle()){//相关跳转
                    case "普通货源":
                        CargoManageActivity.start(getActivity(),true);
                        break;
                    case "竞价货源":
                        CargoManageActivity.start(getActivity(),false);
                        break;
                    case "承运商机":
                        CarriageBusinessActivity.start(getActivity());
                        break;
                    case "运输订单":
                        TransportOrderOwnerActivity.start(getActivity());
                        break;
                    case "我的询价":
                        BargainingActivity.start(getActivity());
                        break;

                }
            }
        });


    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
        }

    }
}
